home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.rock;
-
- import java.awt.Image;
- import java.awt.image.ColorModel;
- import java.awt.image.ImageConsumer;
- import java.awt.image.ImageProducer;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.Hashtable;
-
- public abstract class ImageEncoder implements ImageConsumer {
- protected boolean allowAccumulate;
- protected OutputStream out;
- private ImageProducer producer;
- private int width;
- private int height;
- private int hintflags;
- private boolean started;
- private boolean encoding;
- private IOException iox;
- private static final ColorModel rgbModel = ColorModel.getRGBdefault();
- private Hashtable props;
- private RgbMangler defaultRgbMangler;
- private RgbMangler currentMangler;
- private boolean accumulate;
- private int[] accumulator;
-
- public ImageEncoder(Image var1, OutputStream var2) throws IOException {
- this(var1.getSource(), var2);
- }
-
- public ImageEncoder(ImageProducer var1, OutputStream var2) throws IOException {
- this.allowAccumulate = true;
- this.width = -1;
- this.height = -1;
- this.hintflags = 0;
- this.started = false;
- this.props = null;
- this.defaultRgbMangler = new 1((ImageEncoder)null);
- this.currentMangler = this.defaultRgbMangler;
- this.accumulate = false;
- this.producer = var1;
- this.out = var2;
- }
-
- public void setColorMangler(RgbMangler var1) {
- this.currentMangler = var1;
- }
-
- abstract void encodeStart(int var1, int var2) throws IOException;
-
- abstract void encodePixels(int var1, int var2, int var3, int var4, int[] var5, int var6, int var7) throws IOException;
-
- abstract void encodeDone() throws IOException;
-
- public synchronized void encode() throws IOException {
- this.encoding = true;
- this.iox = null;
- this.producer.startProduction(this);
-
- while(this.encoding) {
- try {
- this.wait();
- } catch (InterruptedException var2) {
- }
- }
-
- if (this.iox != null) {
- throw this.iox;
- }
- }
-
- private void encodePixelsWrapper(int var1, int var2, int var3, int var4, int[] var5, int var6, int var7) throws IOException {
- if (!this.started) {
- this.started = true;
- this.encodeStart(this.width, this.height);
- if ((this.hintflags & 2) == 0 && this.allowAccumulate) {
- this.accumulate = true;
- this.accumulator = new int[this.width * this.height];
- }
- }
-
- if (this.accumulate) {
- for(int var8 = 0; var8 < var4; ++var8) {
- System.arraycopy(var5, var8 * var7 + var6, this.accumulator, (var2 + var8) * this.width + var1, var3);
- }
- } else {
- this.encodePixels(var1, var2, var3, var4, var5, var6, var7);
- }
-
- }
-
- private void encodeFinish() throws IOException {
- if (this.accumulate) {
- this.encodePixels(0, 0, this.width, this.height, this.accumulator, 0, this.width);
- this.accumulator = null;
- this.accumulate = false;
- }
-
- }
-
- private synchronized void stop() {
- this.encoding = false;
- this.notifyAll();
- }
-
- public void setDimensions(int var1, int var2) {
- this.width = var1;
- this.height = var2;
- }
-
- public void setProperties(Hashtable var1) {
- this.props = var1;
- }
-
- public void setColorModel(ColorModel var1) {
- }
-
- public void setHints(int var1) {
- this.hintflags = var1;
- }
-
- public void setPixels(int var1, int var2, int var3, int var4, ColorModel var5, byte[] var6, int var7, int var8) {
- int[] var9 = new int[var3];
-
- for(int var10 = 0; var10 < var4; ++var10) {
- int var11 = var7 + var10 * var8;
-
- for(int var12 = 0; var12 < var3; ++var12) {
- var9[var12] = this.currentMangler.mangleRGBValue(var5.getRGB(var6[var11 + var12] & 255));
- }
-
- try {
- this.encodePixelsWrapper(var1, var2 + var10, var3, 1, var9, 0, var3);
- } catch (IOException var14) {
- this.iox = var14;
- this.stop();
- return;
- }
- }
-
- }
-
- public void setPixels(int var1, int var2, int var3, int var4, ColorModel var5, int[] var6, int var7, int var8) {
- int[] var9 = new int[var3];
-
- for(int var10 = 0; var10 < var4; ++var10) {
- int var11 = var7 + var10 * var8;
- if (var5 == rgbModel) {
- for(int var14 = 0; var14 < var3; ++var14) {
- var9[var14] = this.currentMangler.mangleRGBValue(var6[var11 + var14]);
- }
- } else {
- for(int var12 = 0; var12 < var3; ++var12) {
- var9[var12] = this.currentMangler.mangleRGBValue(var5.getRGB(var6[var11 + var12]));
- }
- }
-
- try {
- this.encodePixelsWrapper(var1, var2 + var10, var3, 1, var9, 0, var3);
- } catch (IOException var13) {
- this.iox = var13;
- this.stop();
- return;
- }
- }
-
- }
-
- public void imageComplete(int var1) {
- this.producer.removeConsumer(this);
- if (var1 == 4) {
- this.iox = new IOException("image aborted");
- } else {
- try {
- this.encodeFinish();
- this.encodeDone();
- } catch (IOException var3) {
- this.iox = var3;
- }
- }
-
- this.stop();
- }
- }
-